const pool = require('mysql2/promise').createPool({ //创建连接池
    user: 'mydb',
    password: 'mydb',
    database: 'testmydb',
});


pool.getConnection()
    .then(conn => {
        const res = conn.query('SELECT * FROM bookinfo');
        conn.release();
        return res;
    }).then(result => {
        console.log(result);
    }).catch(err => {
        console.log(err); //以上任何连接时或查询时错误
    });